﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Net.Http;
using System.Runtime.Serialization.Json;
using tricogol.app.Data;

namespace tricogol.metro.Servicio
{
    public class EncuentroService
    {
        public ObservableCollection<cn_encuentro> objetoreturn;
        public async void ObtenetEncuentros() 
        {
            string Url = "http://tricogol.azurewebsites.net/api/Encuentro/";
            using (HttpClient clienteHttp = new HttpClient()) 
            {
                HttpResponseMessage response = await clienteHttp.GetAsync(Url);
                response.EnsureSuccessStatusCode();

                using (var stream = await response.Content.ReadAsStreamAsync())
                {
                    const string dateFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ";

                    var settings = new DataContractJsonSerializerSettings
                    {
                        DateTimeFormat = new System.Runtime.Serialization.DateTimeFormat(dateFormat)
                    };

                    
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ObservableCollection<cn_encuentro>), settings);

                    objetoreturn = serializer.ReadObject(stream) as ObservableCollection<cn_encuentro>;

                    
                }
            }

        }
       
    }
}
